<?php
require_once("init.php");
require_once("inc/header.php");
?>
<div id="tweets">
<?php
$page=$_GET['page'];
if(!intval($page)>0) $page=1;

$filter=$_GET['filter'];
if($filter=="") $filter="all";

$type=$_GET['type'];
switch($type){
	case "timeline":
		$url="http://twitter.com/statuses/friends_timeline.json?page=".$page;
		break;
	case "mentions":
		$url="http://twitter.com/statuses/mentions.json?page=".$page;
		break;
	case "favs":
		$url="http://twitter.com/favorites.json?page=".$page;
		break;
    case "profile":
        $url="http://twitter.com/statuses/user_timeline.json";
        break;
	default:
		$url="http://twitter.com/statuses/friends_timeline.json?page=".$page;
		break;
}

$timeline=obj_to_array(get_from_twitter($url));
//$timeline=tweet_filter($timeline,$filter);
$i=0;

//echo date('Y-m-d H:i:s').'<br>';
//get tweets ratings from cache
$tweets_cache = get_tweets_from_cache();

foreach($timeline as $msg) {
	$i+=1;
	show_msg($i,$msg,$type,$page,$tweets_cache);
}
//echo date('Y-m-d H:i:s').'<br>';
//update cache
delete_cache();
if($page>1){
	echo "<a href='index.php?type=".$type."&filter=".$filter."&page=".($page-1)."'>prev</a> ";
}
echo "<a href='index.php?type=".$type."&filter=".$filter."&page=".($page+1)."'>next</a> ";
?>
</div>
<?php
require_once("inc/footer.php");
?>